"""
@FileName：all_citys.py.py\n
@Description：\n
@Author：lssyyr\n
@Time：2024/12/8 23:10\n
"""
import requests
import re
import os
if not os.path.exists('../images'):
    os.mkdir('../images')
url = 'https://movie.douban.com/top250'
headers ={
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0'
}
response = requests.get(url, headers=headers).text
pattern = r'<img\s+[^>]*alt="([^"]*)"\s+[^>]*src="([^"]*)"[^>]*>'
matches = re.findall(pattern,response)
for alt, src in matches:
    img_data = requests.get(src, headers=headers).content
    img_nameold = src.split('/')[-1]
    img_gs = img_nameold.split('.')[-1]
    img_name = alt+'.'+img_gs
    img_path = './images/'+img_name
    print(f"Alt: {alt}")
    print(f"Src: {src}")
    with open(img_path, 'wb') as fp:
        fp.write(img_data)
        print(img_name,'下载成功')